package com.easy.component.loadingmore;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.easy.component.R;

/**
 * 描述: {描述}
 * 作者: jack-song
 * 创建日期: 2017/11/15 10:29
 * 修改日期: 2017/11/15
 * 版本: {版本}
 */
public class BaseMoreView extends RelativeLayout implements MoreView {
    private ProgressBar mPbLoading;
    private TextView mTvMessage;
    public BaseMoreView(Context context) {
        super(context);
        init(context);
    }

    public BaseMoreView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public BaseMoreView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public BaseMoreView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {
        inflate(context, R.layout.easy_more_refresh_load_more, this);;
        mPbLoading = (ProgressBar) findViewById(R.id.pull_to_refresh_progress);
        mTvMessage = (TextView) findViewById(R.id.load_more);
    }

    /**
     * 显示普通布局
     */
    @Override
    public void showNormal() {
        mPbLoading.setVisibility(View.GONE);
        mTvMessage.setText(R.string.easy_more_pull_to_refresh_pull_up_label);
    }

    /**
     * 显示正在加载中的布局
     */
    @Override
    public void showLoading() {
        mPbLoading.setVisibility(View.VISIBLE);
        mTvMessage.setText(R.string.easy_more_p2refresh_doing_end_refresh);
    }
    /**
     * 显示已经加载完成，没有更多数据的布局
     */
    @Override
    public void showNoMore() {
        mPbLoading.setVisibility(View.GONE);
        mTvMessage.setText(R.string.easy_more_loading_view_no_more);
    }
    /**
     * 显示加载失败的布局
     */
    @Override
    public void showFail() {
        mPbLoading.setVisibility(View.GONE);
        mTvMessage.setText(R.string.easy_more_loading_view_net_error);
    }
    /**
     * 获取footerview
     * @return
     */
    @Override
    public View getFooterView() {
        return this;
    }
}
